# coding:utf-8
# writingtime: 2022-8-2
# reference: https://doi.org/10.1007/s40815-021-01243-2
from math import log


class PartitionCoefficient:
    @staticmethod
    def getresult(dataList, membershipMatrix, clusterCenter, m=2, a=2):
        """
        function: Partition Coefficient评价函数
        :param membershipMatrix: 评价矩阵
        :return:membershipMatrix的分配系数
        """
        coefficient = sum([sum([j * j for j in i]) for i in membershipMatrix])

        return coefficient


class PartitionEntropy:
    @staticmethod
    def getresult(dataList, membershipMatrix, clusterCenter, m=2, a=2):
        """
        function: Partition Entropy评价函数
        :param membershipMatrix: 评价矩阵
        :param a: Partition Entropy评价函数的参数
        :return:membershipMatrix的熵
        """
        entropy = - sum([sum([j * log(j, a) for j in i]) for i in membershipMatrix])

        return entropy
